package study.java.jvm.service;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import study.java.jvm.controller.mem.heap.HeapObject;

import javax.annotation.PostConstruct;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class HeapService {

    private ExecutorService pool = new ThreadPoolExecutor(1, 1,
            0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(10000));

    @PostConstruct
    public void init() {
        new Thread(() -> {
        }).start();
    }

    public void doTest(HeapObject obj) {

        pool.execute(() -> {
            log.info("{}", obj);
            ThreadUtil.sleep(10 * 1000);
        });
    }
}
